home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / embedded / m68k / cc68k.arc / PREPROC.C < prev    next >
C/C++ Source or Header  |  1986-10-26  |  3KB  |  88 lines

  1. #include        "stdio.h"
  2. #include        "string.h"
  3. #include        "c.h"
  4. #include        "expr.h"
  5. #include        "gen.h"
  6. #include        "cglbdec.h"
  7.  
  8.  
  9. /*
  10.  *    68000 C compiler
  11.  *
  12.  *    Copyright 1984, 1985, 1986 Matthew Brandt.
  13.  *  all commercial rights reserved.
  14.  *
  15.  *    This compiler is intended as an instructive tool for personal use. Any
  16.  *    use for profit without the written consent of the author is prohibited.
  17.  *
  18.  *    This compiler may be distributed freely for non-commercial use as long
  19.  *    as this notice stays intact. Please forward any enhancements or questions
  20.  *    to:
  21.  *
  22.  *        Matthew Brandt
  23.  *        Box 920337
  24.  *        Norcross, Ga 30092
  25.  */
  26.  
  27. FILE            *inclfile[10];
  28. int             incldepth = 0;
  29. int             inclline[10];
  30. char            *lptr;
  31.  
  32. int  preprocess()
  33. {       ++lptr;
  34.         lastch = ' ';
  35.         getsym();               /* get first word on line */
  36.         if( lastst != id ) {
  37.                 error(ERR_PREPROC);
  38.                 return getline(incldepth == 0);
  39.                 }
  40.         if( strcmp(lastid,"include") == 0 )
  41.                 return doinclude();
  42.         else if( strcmp(lastid,"define") == 0 )
  43.                 return dodefine();
  44.         else    {
  45.                 error(ERR_PREPROC);
  46.                 return getline(incldepth == 0);
  47.                 }
  48. }
  49.  
  50. int doinclude()
  51. {       int     rv;
  52.         getsym();               /* get file to include */
  53.         if( lastst != sconst ) {
  54.                 error(ERR_INCLFILE);
  55.                 return getline(incldepth == 0);
  56.                 }
  57.         inclline[incldepth] = lineno;
  58.         inclfile[incldepth++] = input;  /* push current input file */
  59.         input = fopen(laststr,"r");
  60.         if( input == 0 ) {
  61.                 input = inclfile[--incldepth];
  62.                 error(ERR_CANTOPEN);
  63.                 rv = getline(incldepth == 0);
  64.                 }
  65.         else    {
  66.                 rv = getline(incldepth == 1);
  67.                 lineno = -32768;        /* dont list include files */
  68.                 }
  69.         return rv;
  70. }
  71.  
  72. int dodefine()
  73. {       SYM     *sp;
  74.         getsym();               /* get past #define */
  75.         if( lastst != id ) {
  76.                 error(ERR_DEFINE);
  77.                 return getline(incldepth == 0);
  78.                 }
  79.         ++global_flag;          /* always do #define as globals */
  80.         sp =(SYM *) xalloc(sizeof(SYM));
  81.         sp->name =(char *)litlate(lastid);
  82.         sp->value.s =(char *) litlate(lptr);
  83.         insert(sp,&defsyms);
  84.         --global_flag;
  85.         return getline(incldepth == 0);
  86. }
  87.  
  88.